<template>
  <div class="building-type-test" name="BuildingTypeTest">
    <div class="test-container" name="TestContainer">
      <div class="test-header" name="TestHeader">
        <h2>建筑类型选择器测试页面</h2>
        <p>测试跨划分方式选择功能，切换划分方式后不会清空之前的选择</p>
      </div>
      
      <div class="test-content" name="TestContent">
        <!-- 建筑类型选择器 -->
        <BuildingTypeSelector
          name="BuildingTypeSelector"
          v-model="selectedCategories"
          :max-select="10"
          @change="handleCategoryChange"
        />
        
        <!-- 测试结果展示 -->
        <div class="test-results" name="TestResults">
          <h3>测试结果</h3>
          <div class="result-item">
            <strong>选择的类型ID:</strong>
            <pre>{{ JSON.stringify(selectedCategories, null, 2) }}</pre>
          </div>
          <div class="result-item">
            <strong>组合结果:</strong>
            <pre>{{ combinedResult }}</pre>
          </div>
          <div class="result-item">
            <strong>选择数量:</strong>
            <span>{{ selectedCategories.length }}</span>
          </div>
        </div>
        
        <!-- 测试操作 -->
        <div class="test-actions" name="TestActions">
          <h3>测试操作</h3>
          <el-button @click="clearSelection" type="danger">清空选择</el-button>
          <el-button @click="addMockData" type="primary">添加模拟数据</el-button>
          <el-button @click="testSwitchDivision" type="warning">测试切换划分方式</el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { ElMessage } from 'element-plus'
import BuildingTypeSelector from '@/components/BuildingTypeSelector/index.vue'

// 响应式数据
const selectedCategories = ref<number[]>([])
const combinedResult = ref<string>('')

// 处理分类选择变化
const handleCategoryChange = (categories: number[], result: string) => {
  selectedCategories.value = categories
  combinedResult.value = result
  console.log('选择变化:', { categories, result })
}

// 清空选择
const clearSelection = () => {
  selectedCategories.value = []
  combinedResult.value = ''
  ElMessage.success('已清空选择')
}

// 添加模拟数据
const addMockData = () => {
  // 添加一些模拟的选择数据
  selectedCategories.value = [11, 21, 31] // 住宅 + 框架结构 + 低层建筑
  ElMessage.success('已添加模拟数据')
}

// 测试切换划分方式
const testSwitchDivision = () => {
  ElMessage.info('请手动切换不同的建筑划分方式，观察已选择的类型是否被保留')
}
</script>

<style scoped>
.building-type-test {
  padding: 20px;
  background: #f5f5f5;
  min-height: 100vh;
}

.test-container {
  max-width: 1200px;
  margin: 0 auto;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.test-header {
  padding: 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  text-align: center;
}

.test-header h2 {
  margin: 0 0 10px 0;
  font-size: 24px;
  font-weight: 600;
}

.test-header p {
  margin: 0;
  font-size: 14px;
  opacity: 0.9;
}

.test-content {
  padding: 20px;
}

.test-results {
  margin-top: 30px;
  padding: 20px;
  background: #f8f9fa;
  border-radius: 6px;
  border: 1px solid #e9ecef;
}

.test-results h3 {
  margin: 0 0 16px 0;
  font-size: 18px;
  color: #495057;
  border-bottom: 2px solid #dee2e6;
  padding-bottom: 8px;
}

.result-item {
  margin-bottom: 16px;
}

.result-item strong {
  display: block;
  margin-bottom: 8px;
  color: #495057;
  font-size: 14px;
}

.result-item pre {
  background: #fff;
  border: 1px solid #dee2e6;
  border-radius: 4px;
  padding: 12px;
  margin: 0;
  font-size: 12px;
  color: #6c757d;
  overflow-x: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.result-item span {
  font-size: 16px;
  font-weight: 600;
  color: #28a745;
}

.test-actions {
  margin-top: 30px;
  padding: 20px;
  background: #f8f9fa;
  border-radius: 6px;
  border: 1px solid #e9ecef;
}

.test-actions h3 {
  margin: 0 0 16px 0;
  font-size: 18px;
  color: #495057;
  border-bottom: 2px solid #dee2e6;
  padding-bottom: 8px;
}

.test-actions .el-button {
  margin-right: 12px;
  margin-bottom: 8px;
}
</style>
